{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Hello numpy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.tensor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]]\n"
     ]
    }
   ],
   "source": [
    "x = np.arange(12).reshape(2,6)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.1点积运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 3, 2, 3)\n",
      "[[[[  42   48   54]\n",
      "   [ 114  120  126]]\n",
      "\n",
      "  [[ 114  136  158]\n",
      "   [ 378  400  422]]\n",
      "\n",
      "  [[ 186  224  262]\n",
      "   [ 642  680  718]]]\n",
      "\n",
      "\n",
      " [[[ 258  312  366]\n",
      "   [ 906  960 1014]]\n",
      "\n",
      "  [[ 330  400  470]\n",
      "   [1170 1240 1310]]\n",
      "\n",
      "  [[ 402  488  574]\n",
      "   [1434 1520 1606]]]]\n"
     ]
    }
   ],
   "source": [
    "x1 = np.arange(24).reshape(2,3,4)\n",
    "y1 = np.arange(24).reshape(2,4,3)\n",
    "\n",
    "z1 = x1.dot(y1)\n",
    "print(z1.shape)\n",
    "print(z1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2逐元素乘积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 3, 4)\n",
      "[[[  0   1   4   9]\n",
      "  [ 16  25  36  49]\n",
      "  [ 64  81 100 121]]\n",
      "\n",
      " [[  0  13  28  45]\n",
      "  [ 64  85 108 133]\n",
      "  [160 189 220 253]]]\n"
     ]
    }
   ],
   "source": [
    "x2 = np.arange(24).reshape(2,3,4)\n",
    "y2 = np.arange(12).reshape(3,4)\n",
    "\n",
    "z2 = x2*y2\n",
    "print(z2.shape)\n",
    "print(z2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "operands could not be broadcast together with shapes (2,3,4) (3,) ",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-23-960e3b3dc9be>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0my3\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mz3\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mx2\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0my3\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,4) (3,) "
     ]
    }
   ],
   "source": [
    "y3 = np.arange(3)\n",
    "\n",
    "z3 = x2*y3"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
